home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / phone / ph_iouser.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  6.0 KB  |  214 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3. /*
  4.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  5.  *     
  6.  *
  7.  *     Copyright (C) 1979,1980,1981  University of Delaware
  8.  *     
  9.  *     Department of Electrical Engineering
  10.  *     University of Delaware
  11.  *     Newark, Delaware  19711
  12.  *
  13.  *     Phone:  (302) 738-1163
  14.  *     
  15.  *     
  16.  *     This program module was developed as part of the University
  17.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  18.  *     
  19.  *     Acquisition, use, and distribution of this module and its listings
  20.  *     are subject restricted to the terms of a license agreement.
  21.  *     Documents describing systems using this module must cite its source.
  22.  *
  23.  *     The above statements must be retained with all copies of this
  24.  *     program and may not be removed without the consent of the
  25.  *     University of Delaware.
  26.  *     
  27.  *
  28.  *     version  -1    David H. Crocker    March   1979
  29.  *     version   0    David H. Crocker    April   1980
  30.  *     version  v7    David H. Crocker    May     1981
  31.  *     version   1    David H. Crocker    October 1981
  32.  *
  33.  */
  34. /*#define RUNALON   */
  35.  
  36. /*                  Handle telephone-based i/o                          */
  37.  
  38. /*  Jul, 80 Dave Crocker    remove ph_d_started setting from ph_init    */
  39. /*  Feb, 82 D. Long        improved ll_log hdr field for wider chan name */
  40. /*  Mar, 84 D. Long         added use of per-channel phone transcript */
  41.  
  42. #include "d_returns.h"
  43. #include "ch.h"
  44. #include "phs.h"
  45.  
  46. extern time_t time ();
  47. extern Chan *curchan;
  48. extern struct ll_struct   *logptr,
  49.                ph_log;
  50. extern char *logdfldir;
  51. extern char *tbldfldir;
  52. extern char *def_trn;             /* straight transcript of char i/o    */
  53.  
  54. LOCVAR char ph_d_started;         /* called dial package yet?           */
  55. LOCVAR char *ph_trn;          /* filled-out version of phone trn file */
  56. LOCVAR char *ph_script;           /* filled-out version of dialing script */
  57.  
  58. /*  ********  (ph_)  PHONE MAIL MASTER INIT/END SUB-MODULE  ********** */
  59.  
  60. ph_init ()              /* call remote, to do mail            */
  61. {
  62.     extern char *dupfpath ();
  63.     short     retval;
  64.  
  65. #ifdef DEBUG
  66.     ll_log (logptr, LLOGBTR, "ph_init ()");
  67. #endif
  68.     if (ph_d_started)             /* tried before?                      */
  69.     {
  70.     ph_end (NOTOK);           /* make sure old channel gone         */
  71.     sleep (10);               /* just for the hell of it            */
  72.     ll_log (logptr, LLOGTMP, "[ REDIAL ]");
  73.     printx ("re-");
  74.     }
  75.     else
  76.     {
  77. /*    ll_hdinit (&ph_log, " D");   /* header unique for send             */
  78.     ll_hdinit (&ph_log, logptr -> ll_hdr);   /* init header for send    */
  79. /*    ph_log.ll_hdr[0] = logptr -> ll_hdr[0];  */
  80.     ph_log.ll_hdr[0] = 'D';  /* unique letter for send */
  81.     ph_log.ll_file = dupfpath (ph_log.ll_file, logdfldir);
  82.                    /* fill-out path to log files        */
  83.  
  84.     ph_script = dupfpath (curchan -> ch_script, tbldfldir);
  85.  
  86.     if (curchan -> ch_trans == (char *) DEFTRANS)
  87.         ph_trn = dupfpath (def_trn, logdfldir);
  88.     else
  89.         ph_trn = dupfpath (curchan -> ch_trans, logdfldir);
  90.  
  91.     ll_log (logptr, LLOGGEN, "dialing");
  92.     }
  93.     printx ("dialing... ");
  94.     fflush (stdout);
  95. #ifndef RUNALON
  96.     ph_d_started = TRUE;
  97.     phs_note (curchan, PHS_CNSTRT);
  98.                   /* note WHICH phone channel           */
  99.     if ((retval = d_masconn (ph_script, &ph_log, TRUE, ph_trn,
  100.                 (ph_log.ll_level >= LLOGBTR) ? TRUE : FALSE))
  101.         < D_OK)
  102.     {
  103.     printx ("couldn't connect...\r\n\t");
  104.     retval = ph_d2rpval (retval);
  105.                   /* map return to rp.h value           */
  106.     ll_log (logptr, LLOGTMP,
  107.             "unable to connect (%s)", rp_valstr (retval));
  108.     return (retval);
  109.     }
  110. #endif
  111.  
  112.     printx ("\007connected...\r\n\t");
  113.     fflush (stdout);
  114.     phs_note (curchan, PHS_CNGOT);
  115.     return (RP_OK);
  116. }
  117. /* */
  118.  
  119. ph_end (type)                     /* done with mail process             */
  120. short     type;                     /* clean / dirty ending               */
  121. {
  122.  
  123. #ifdef DEBUG
  124.     ll_log (logptr, LLOGBTR, "ph_end ()");
  125. #endif
  126.  
  127.     if (ph_d_started)             /* is phone channel even active?      */
  128.     {
  129.     ph_d_started = FALSE;
  130.     if (type == OK)           /* try clean good end                 */
  131.     {
  132.         if (rp_isgood (ph_wrec ("end", 3)))
  133.         {                     /* should also look for the reply     */
  134.         d_masdrop (0, TRUE);
  135.                   /* finish the script                  */
  136.         phs_end(curchan, RP_OK);
  137.         return;
  138.         }
  139.     }
  140. #ifndef RUNALON
  141.     else                      /* clean bad end                      */
  142.         d_masdrop (0, 0);     /* don't finish the script            */
  143. #endif
  144.  
  145.     phs_end(curchan, RP_NO);
  146.     return;
  147.     }
  148. }
  149. /* */
  150.  
  151. ph_sbinit ()                      /* ready to submit to remote site     */
  152. {
  153.     struct rp_bufstruct thereply;
  154.     int       len;
  155.  
  156. #ifdef DEBUG
  157.     ll_log (logptr, LLOGBTR, "ph_sbinit ()");
  158. #endif
  159.     if (rp_isbad (ph_wrec ("submit", 6)) ||
  160.         rp_isbad (ph_rrply ((struct rp_bufstruct  *) & thereply,
  161.                                                    &len)) ||
  162.                                                 rp_isbad (thereply.rp_val))
  163.     {
  164.                             ll_log (logptr, LLOGFAT, "can't submit");
  165.     return (RP_NO);
  166.     }
  167. #ifdef DEBUG
  168.     ll_log (logptr, LLOGBTR, "starting to submit");
  169. #endif
  170.     return (RP_OK);
  171. }
  172.  
  173. ph_sbend ()                       /* done with submission               */
  174. {
  175. #ifdef DEBUG
  176.     ll_log (logptr, LLOGBTR, "ph_sbend ()");
  177. #endif
  178.  
  179.     if (rp_isbad (ph_wrec ((char *) 0, 0)))
  180.     {
  181.     ll_log (logptr, LLOGTMP, "bad sbend()");
  182.     return (RP_NO);
  183.     }
  184.     return (RP_OK);
  185. }
  186. /* */
  187.  
  188. ph_pkinit ()                      /* initialize remote pickup            */
  189. {
  190.     struct rp_bufstruct thereply;
  191.     int       len;
  192.  
  193. #ifdef DEBUG
  194.     ll_log (logptr, LLOGPTR, "ph_pkinit ()");
  195. #endif
  196.     if (rp_isbad (ph_wrec ("pickup", 6)) ||
  197.         rp_isbad (ph_rrply ((struct rp_bufstruct  *) & thereply,
  198.                                                    &len)) ||
  199.                                                 rp_isbad (thereply.rp_val))
  200.     {
  201.                             ll_log (logptr, LLOGFAT, "can't pickup");
  202.     return (RP_NO);
  203.     }
  204.     return (RP_OK);
  205. }
  206.  
  207. ph_pkend ()                       /* done with pickup                   */
  208. {
  209. #ifdef DEBUG
  210.     ll_log (logptr, LLOGBTR, "ph_pkend ()");
  211. #endif
  212.     return (RP_OK);
  213. }
  214.